//  应用全量路径正则
export const AppFullReg = /PSSYSAPPS[\/\\]{1,2}[a-zA-Z0-9_]*/g
//  应用路径正则
export const AppReg = /[a-zA-Z0-9_]*/g

/**
 * @description 校验应用路径
 * @param {string} path
 * @return {*}  {boolean}
 */
export function checkAppPath(path: string): boolean {
  if (path == '' || path == undefined || path.search(AppFullReg) != -1 || path.search(AppReg) != -1) {
    return true;
  }
  return false;
}

//  应用下视图路径正则
export const ViewInAppReg = /\/PSSYSAPPS[\/\\]{1,2}[a-zA-Z0-9_]*[\/\\]PSAPPDEVIEWS[\/\\]{1,2}[\w]*.json/g
//  视图全量路径正则
export const ViewFullReg = /PSAPPDEVIEWS[\/\\]{1,2}[\w]*.json/g
//  视图路径正则
export const ViewReg = /[\w]*.json/g

/**
 * @description 校验视图路径
 * @param {string} path
 * @return {*}  {boolean}
 */
export function checkViewPath(path: string): boolean {
  if (path.search(ViewInAppReg) != -1 || path.search(ViewFullReg) != -1 || path.search(ViewReg) != -1) {
    return true;
  }
  return false;
}

//  应用下部件路径正则
export const ControlInAppReg = /PSSYSAPPS[\/\\]{1,2}[a-zA-Z0-9_]*[\/\\]PSAPPDATAENTITIES[\/\\]{1,2}[\w]*[\/\\]{1,2}[\w]*[\/\\]{1,2}[\w]*.json/g
//  部件全量路径正则
export const ControlFullReg = /PSAPPDATAENTITIES[\/\\]{1,2}[\w]*[\/\\]{1,2}[\w]*[\/\\]{1,2}[\w]*.json/g
//  部件路径正则
export const ControlReg = /[\w]*[\/\\]{1,2}[\w]*[\/\\]{1,2}[\w]*.json/g

/**
 * @description 校验部件路径
 * @param {string} path
 * @return {*}  {boolean}
 */
export function checkControlPath(path: string): boolean {
  if (path.search(ControlInAppReg) != -1 || path.search(ControlFullReg) != -1 || path.search(ControlReg) != -1) {
    return true;
  }
  return false;
}

/**
 * @description 校验路径是否正确
 * @export
 * @param {string} type 类型
 * @param {string} path 路径
 * @return {*} 
 */
export function check(type: string, path: string): boolean {
  if (type == 'APP') {
    return checkAppPath(path);
  }
  if (type == 'VIEW') {
    return checkViewPath(path);
  }
  if (type == 'CONTROL') {
    return checkControlPath(path);
  }
  return false;
}